#coding=utf-8
'''
    足底压力传感器原始数据
'''


import numpy as np

import pyqtgraph as pg
import pyqtgraph.opengl as gl

class PressureWidget(gl.GLViewWidget):
    '''
        用于显示足底压力的类(双足)
    '''
    def __init__(self,parent=None,barSize=0.5,positionRel=[[3.5,2.0,0.0],[3.5,-2.0,0.0],[-3.5,2.0,0.0],[-3.5,-2.0,0.0]],rCoord=[-0.25,-5.25,0.0],lCoord=[-0.25,4.75,0.0]):
        super().__init__()
        self.lCoord=np.tile(np.array(lCoord),(4,1))
        self.rCoord = np.tile(np.array(rCoord), (4, 1))
        self.posL=np.array(positionRel)+self.lCoord
        self.posR=np.array(positionRel)+self.rCoord
        self.poses=np.vstack((self.posL,self.posR))

        self.sizes=np.ones((8,3))*barSize  #     一共8各传感器
        #   添加网格
        self.addItem(gl.GLGridItem())
        self.addItem(gl.GLAxisItem())
        #   Bar图
        self.bar=gl.GLBarGraphItem(self.poses,self.sizes)
        self.addItem(self.bar)
        #   标题
        self.setWindowTitle("足底压力传感器数值")
    def UpdateData(self,valueL,valueR):
        '''
        更新压力数据
        :return:
        '''
        self.sizes[0:4,2]=valueL
        self.sizes[4:8,2]=valueR
        self.removeItem(self.bar)
        self.bar = gl.GLBarGraphItem(self.poses, self.sizes)
        self.addItem(self.bar)

if __name__ == '__main__':
    app = pg.mkQApp("GLBarGraphItem Example")
    w=PressureWidget()
    w.show()
    w.UpdateData(np.array([1,1,1,1]),np.array([0.5,0.5,0.5,0.5]))
    pg.exec()
